package cn.jn.lhm.oss.handler;

import cn.jn.lhm.oss.service.OssService;
import cn.jn.lhm.utils.R;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author LHM
 * @Tips 热爱每一天，奋斗每一天
 * @date 2020/5/30 - 20:18
 */
@RestController
@RequestMapping("/oss")
public class OssHandler {

    @Resource
    private OssService ossService;

    @PostMapping("/file/upload")
    public R uploadFile(MultipartFile file){

        //返回上传的头像的路径
        String url = ossService.uploadFileAvatar(file);
        if (url == null){
            return R.error().message("文件上传失败");
        }
        return R.ok().data("url",url);
    }
}
